#include <stdio.h>
#include <stdlib.h>

void ave(int *, int, int);

int main()
{
	int matrix[3][2] = {{1, 2}, {4, 2}, {5, 5}};
	printf("test1\n");
	ave(matrix, 3, 2);
	return 0;
}

void ave(int * matrix, int m, int n)
{
	printf("test2\n");
	float * col_ave = malloc(n * sizeof(float));
	float * row_ave = malloc(m * sizeof(float));
	int i,j;
	printf("test3\n");
	for(i = 0; i < m; i++)
	{
		int sum = 0;
		for(j = 0; j < n; j++)
		{
			sum+=matrix[i*n+j];
			printf("%d\t", matrix[i*n + j]);
		}
		row_ave[i] = (float)sum / n;
		printf("ave:%f\n",row_ave[i]);
	}
	for(i = 0; i < n; i++)
	{
		int sum = 0;
		for(j = 0; j < m; j++)sum+=matrix[i + j*n];
		col_ave[i] = (float)sum / m;
		printf("%.4f\t", col_ave[i]);
	}
	printf("<-ave\n");
	free(col_ave);
	free(row_ave);
}
